$(function () {
    var token = localStorage.token;
    var plist = JSON.parse(localStorage.sureOrderProductDetail);
    var totalDiamond = 0;
    var totalCash = 0;
    $.each(plist, function (index, value) {
        totalDiamond += parseFloat(value.diamond) * parseInt(value.count);
        totalCash += parseFloat(value.cash) * parseInt(value.count);
    });
    console.log(totalDiamond);
    $.ajax({
        type: "get",
        url: domain.test + "/carcalculate",
        beforeSend: function (xhr) {
            xhr.setRequestHeader("token", token);
        },
        success: function (response) {
            console.log(response);
            if (response.data.rtnCode === 200) {
                var sureOrderDetail = response.data.data;
                sureOrderDetail.pList = JSON.parse(localStorage.sureOrderProductDetail);
                sureOrderDetail.totalPrice = parseFloat(localStorage.totalPrice);
                sureOrderDetail.totalDiamond = parseFloat(totalDiamond);
                sureOrderDetail.totalCash = parseFloat(totalCash);
                // sureOrderDetail.diamond = 1000;
                sureOrderDetail.gold = 1;
                sureOrderDetail.hongbao = 1000;
                console.log(sureOrderDetail);
                $(".orderDetail").html(template("orderDetail", { sureOrderDetail: sureOrderDetail }));
            }
        }
    });
    //是否选择钻石加现金支付
    $(".orderDetail").on("click", ".diamondBtn", function () {
        if (parseInt($(this).attr("noMoreDiamond")) === 0) return false;
        var goldStatus = parseInt($(".goldBtn").attr("goldStatus"));
        var redPayStatus = parseInt($(".redPayBtn").attr("redPayStatus"));
        if (goldStatus === 0 && redPayStatus === 0) {
            if (parseInt($(this).attr("payType")) === 2) {
                $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                $(this).attr("payType", 1);
                $(".diamondPay").html("0.00");
                $(".wxPay").html(localStorage.totalPrice);
                $(".cashPay").html(localStorage.totalPrice);
            } else if (parseInt($(this).attr("payType")) === 1) {
                $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                $(this).attr("payType", 2);
                $(".diamondPay").html(totalDiamond.toFixed(2));
                $(".wxPay").html(totalCash.toFixed(2));
                $(".cashPay").html(totalCash.toFixed(2));
            }
        }
        if (goldStatus === 1 && redPayStatus === 0) {
            //取消钻石支付
            if (parseInt($(this).attr("payType")) === 2) {
                var coin = parseFloat($(".coinL").html());
                console.log(coin);
                $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                $(this).attr("payType", 1);
                if(totalCash>0) {
                    if (coin > parseFloat(localStorage.totalPrice)) {
                        $(".diamondPay").html("0.00");
                        $(".coinPayD").html(localStorage.totalPrice);
                    } else if (coin < parseFloat(localStorage.totalPrice)) {
                        if (coin - totalCash >= 0) {
                            $(".diamondPay").html("0.00");
                            $(".coinPayD").html(totalCash.toFixed(2));
                            $(".wxPay").html((parseFloat(localStorage.totalPrice) - totalCash).toFixed(2));
                            $(".cashPay").html((parseFloat(localStorage.totalPrice) - totalCash).toFixed(2));
                        } else if (coin - totalCash < 0) {
                            $(".diamondPay").html("0.00");
                            $(".coinPayD").html(coin.toFixed(2));
                            $(".wxPay").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                            $(".cashPay").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                        }
                    }
                }else if(totalCash===0) {
                    if(coin>=parseFloat(localStorage.totalPrice)) {
                        $(".diamondPay").html("0.00");
                        $(".coinPayD").html(parseFloat(localStorage.totalPrice).toFixed(2));
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }else if(coin<parseFloat(localStorage.totalPrice)) {
                        $(".diamondPay").html("0.00");
                        $(".coinPayD").html(coin.toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice)-coin).toFixed(2));
                        $(".cashPay").html((parseFloat(localStorage.totalPrice)-coin).toFixed(2));
                    }
                }
            } else if (parseInt($(this).attr("payType")) === 1) {
                var coin = parseFloat($(".coinL").html());
                if(totalCash>0) {
                    if(coin>=parseFloat(localStorage.totalPrice)) {
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".coinPayD").html(totalCash.toFixed(2));
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }else if(coin<parseFloat(localStorage.totalPrice)) {
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".coinPayD").html(coin.toFixed(2));
                        $(".wxPay").html((totalCash-coin).toFixed(2));
                        $(".cashPay").html((totalCash-coin).toFixed(2));
                    }
                }else if(totalCash===0) {
                    if(coin<parseFloat(localStorage.totalPrice)) {
                        console.log(8888888888888)
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".coinPayD").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }else if(coin>=parseFloat(localStorage.totalPrice)) {
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".coinPayD").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }
                }
            }
        }
        if (goldStatus === 0 && redPayStatus === 1) {
            //取消钻石支付
            if (parseInt($(this).attr("payType")) === 2) {
                var red = parseFloat($(".redL").html());
                $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                $(this).attr("payType", 1);
                if(totalCash>0) {
                    if (red > parseFloat(localStorage.totalPrice)) {
                        $(".diamondPay").html("0.00");
                        $(".redPayD").html(localStorage.totalPrice);
                    } else if (red < parseFloat(localStorage.totalPrice)) {
                        if (red - totalCash >= 0) {
                            $(".diamondPay").html("0.00");
                            $(".redPayD").html(totalCash.toFixed(2));
                            $(".wxPay").html((parseFloat(localStorage.totalPrice) - totalCash).toFixed(2));
                            $(".cashPay").html((parseFloat(localStorage.totalPrice) - totalCash).toFixed(2));
                        } else if (red - totalCash < 0) {
                            $(".diamondPay").html("0.00");
                            $(".redPayD").html(red.toFixed(2));
                            $(".wxPay").html((parseFloat(localStorage.totalPrice) - red).toFixed(2));
                            $(".cashPay").html((parseFloat(localStorage.totalPrice) - red).toFixed(2));
                        }
                    }
                }else if(totalCash===0) {
                    if(red>=parseFloat(localStorage.totalPrice)) {
                        $(".diamondPay").html("0.00");
                        $(".redPayD").html(localStorage.totalPrice);
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }else if(red<parseFloat(localStorage.totalPrice)) {
                        $(".diamondPay").html("0.00");
                        $(".redPayD").html(red.toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice)-red).toFixed(2));
                        $(".cashPay").html((parseFloat(localStorage.totalPrice)-red).toFixed(2));
                    }
                 }
            } else if (parseInt($(this).attr("payType")) === 1) {
                var red = parseFloat($(".redL").html());
                if(totalCash>0) {
                    if(red<totalCash) {
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".redPayD").html(red.toFixed(2));
                        $(".wxPay").html((totalCash-red).toFixed(2));
                        $(".cashPay").html((totalCash-red).toFixed(2));                        
                    }else if(red>=totalCash) {
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".redPayD").html(totalCash.toFixed(2));
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }
                }else if(totalCash===0) {
                    if(red<parseFloat(localStorage.totalPrice)) {
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".redPayD").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }else if(red>parseFloat(localStorage.totalPrice)) {
                        $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                        $(this).attr("payType", 2);
                        $(".diamondPay").html(totalDiamond.toFixed(2));
                        $(".redPayD").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                    }
                }
            }
        }
        if (goldStatus === 1 && redPayStatus === 1) {
            var coin = parseFloat($(".coinL").html());
            var red = parseFloat($(".redL").html());
            if (parseInt($(this).attr("payType")) === 2) {
                if ((coin + red) < totalCash) {
                    $(this).attr("payType", 1);
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(".diamondPay").html("0.00");
                    $(".cashPay").html((parseFloat(localStorage.totalPrice) - (coin + red)).toFixed(2));
                    $(".wxPay").html((parseFloat(localStorage.totalPrice) - (coin + red)).toFixed(2));
                }
                if (coin >= totalCash && coin < parseFloat(localStorage.totalPrice) && red > 0 && red < totalCash) {
                    $(this).attr("payType", 1);
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(".diamondPay").html("0.00");
                    $(".redPayD").html(red.toFixed(2));
                    $(".coinPayD").html(coin.toFixed(2));
                    $(".cashPay").html((parseFloat(localStorage.totalPrice) - (coin + red)).toFixed(2));
                    $(".wxPay").html((parseFloat(localStorage.totalPrice) - (coin + red)).toFixed(2));
                }
                if (coin > parseFloat(localStorage.totalPrice) && red > 0 && red < totalCash) {
                    $(this).attr("payType", 1);
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(".diamondPay").html("0.00");
                    $(".coinPayD").html((parseFloat(localStorage.totalPrice)).toFixed(2));
                    $(".redPayD").html("0.00");
                }
                if (red >= totalCash && red < (parseFloat(localStorage.totalPrice)) && coin > 0 && coin < totalCash) {
                    $(this).attr("payType", 1);
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(".diamondPay").html("0.00");
                    $(".redPayD").html(red.toFixed(2));
                    $(".coinPayD").html(coin.toFixed(2));
                    $(".cashPay").html((parseFloat(localStorage.totalPrice) - (coin + red)).toFixed(2));
                    $(".wxPay").html((parseFloat(localStorage.totalPrice) - (coin + red)).toFixed(2));
                }
                if (red > parseFloat(localStorage.totalPrice) && coin > 0 && coin < totalCash) {
                    $(this).attr("payType", 1);
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(".diamondPay").html("0.00");
                    $(".coinPayD").html(coin.toFixed(2));
                    $(".redPayD").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                }
                if (coin > totalCash && red > totalCash) {
                    $(this).attr("payType", 1);
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(".diamondPay").html("0.00");
                    $(".coinPayD").html((parseFloat(localStorage.totalPrice)).toFixed(2));
                    $(".redPayD").html("0.00");
                    $(".cashPay").html("0.00");
                    $(".wxPay").html("0.00");
                }
                if (coin > totalCash && red > totalCash && totalCash===0) {
                   if(coin>=parseFloat(localStorage.totalPrice)) {
                    $(".coinPayD").html(parseFloat(localStorage.totalPrice));
                    $(".redPayD").html("0.00");
                    $(".cashPay").html("0.00");
                    $(".wxPay").html("0.00");
                   }else if(coin<parseFloat(localStorage.totalPrice)) {
                    $(".coinPayD").html(coin.toFixed(2));
                    if(red>=parseFloat(localStorage.totalPrice)-coin) {
                        $(".redPayD").html((parseFloat(localStorage.totalPrice)-coin).toFixed(2));
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                    }else if(red<parseFloat(localStorage.totalPrice)-coin) {
                        $(".redPayD").html(red.toFixed(2));
                        $(".cashPay").html((parseFloat(localStorage.totalPrice)-coin-red).toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice)-coin-red).toFixed(2));
                    }
                   }
                }
            } else if (parseInt($(this).attr("payType")) === 1) {
                if ((coin + red) < totalCash) {
                    $(this).attr("payType", 2);
                    $(".diamondPay").html(totalDiamond.toFixed(2));
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(".redPayD").html(red.toFixed(2));
                    $(".coinPayD").html(coin.toFixed(2));
                    $(".cashPay").html((totalCash - (coin + red)).toFixed(2));
                    $(".wxPay").html((totalCash - (coin + red)).toFixed(2));
                }
                if (coin >= totalCash && red > 0 && red < totalCash) {
                    $(this).attr("payType", 2);
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(".diamondPay").html(totalDiamond.toFixed(2));
                    $(".redPayD").html(red.toFixed(2));
                    $(".coinPayD").html(coin.toFixed(2));
                    $(".cashPay").html("0.00");
                    $(".wxPay").html("0.00");
                }
                if (red >= totalCash && coin > 0 && coin < totalCash) {
                    $(this).attr("payType", 2);
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(".diamondPay").html(totalDiamond.toFixed(2));
                    $(".redPayD").html((red - coin).toFixed(2));
                    $(".coinPayD").html(coin.toFixed(2));
                    $(".cashPay").html("0.00");
                    $(".wxPay").html("0.00");
                }
                if (red > parseFloat(localStorage.totalPrice) && coin > 0 && coin < totalCash) {
                    $(this).attr("payType", 2);
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(".diamondPay").html(totalDiamond.toFixed(2));
                    $(".coinPayD").html(coin.toFixed(2));
                    $(".redPayD").html((totalCash - coin).toFixed(2));
                }
                if (coin > parseFloat(localStorage.totalPrice) && red > 0 && red < totalCash) {
                    $(this).attr("payType", 2);
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(".diamondPay").html(totalDiamond.toFixed(2));
                    $(".coinPayD").html(totalCash.toFixed(2));
                    $(".redPayD").html("0.00");
                }
                if (coin > totalCash && red > totalCash) {
                    $(this).attr("payType", 2);
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(".diamondPay").html(totalDiamond.toFixed(2));
                    $(".coinPayD").html(totalCash.toFixed(2));
                    $(".redPayD").html("0.00");
                    $(".cashPay").html("0.00");
                    $(".wxPay").html("0.00");
                }
            }
        }
    });
    //使用金币抵扣
    $(".orderDetail").on("click", ".goldBtn", function () {
        var payType = parseInt($(".diamondBtn").attr("payType"));
        var redPayStatus = parseInt($(".redPayBtn").attr("redPayStatus"));
        //现金加钻石支付
        if (payType === 2) {
            if (redPayStatus === 0) {
                // if (totalCash === 0) return false;
                if (parseInt($(this).attr("goldStatus")) === 0) {
                    //使用金币抵扣
                    var coin = parseFloat($(".coinL").html());
                    if(coin===0) return false;
                    //如果金币大于或等于需要支付的现金
                    if (coin >= totalCash) {
                        console.log(00000000)
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".coinPayD").html(totalCash.toFixed(2));
                    } else if (coin < totalCash) {
                        $(".cashPay").html((totalCash - coin).toFixed(2));
                        $(".wxPay").html((totalCash - coin).toFixed(2));
                        $(".coinPayD").html(coin.toFixed(2));
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("goldStatus", 1);
                } else if (parseInt($(this).attr("goldStatus")) === 1) {
                    //取消金币抵扣
                    $(".cashPay").html(totalCash.toFixed(2));
                    $(".wxPay").html(totalCash.toFixed(2));
                    $(".coinPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("goldStatus", 0);
                }
            } else if (redPayStatus === 1) {
                var red = parseFloat($(".redL").html());
                console.log(totalCash);
                if (parseInt($(this).attr("goldStatus")) === 0) {
                    //使用金币抵扣
                    var coin = parseFloat($(".coinL").html());
                    if(coin===0) {
                        return false;
                    }
                    //如果金币大于或等于需要支付的现金
                    if (coin >= totalCash) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".coinPayD").html(totalCash.toFixed(2));
                        $(".redPayD").html("0.00");
                    }
                    else if (coin < (totalCash)) {//-red
                        $(".coinPayD").html(coin.toFixed(2));
                        if (red >= totalCash - coin) {
                            $(".redPayD").html((totalCash - coin).toFixed(2));
                            $(".cashPay").html("0.00");
                            $(".wxPay").html("0.00");
                        } else if (red < totalCash - coin) {
                            $(".redPayD").html(red.toFixed(2));     
                            $(".cashPay").html((totalCash-coin-red).toFixed(2));                            
                            $(".wxPay").html((totalCash-coin-red).toFixed(2));                            
                        }
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("goldStatus", 1);
                } else if (parseInt($(this).attr("goldStatus")) === 1) {
                    console.log(99999999)
                    //取消金币抵扣
                    console.log(totalCash - red);
                    if (totalCash - red >= 0) {
                        $(".cashPay").html((totalCash - red).toFixed(2));
                        $(".wxPay").html((totalCash - red).toFixed(2));
                        $(".redPayD").html(red.toFixed(2));                        
                    } else if (totalCash - red < 0) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".redPayD").html(totalCash.toFixed(2));
                    }
                    $(".coinPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("goldStatus", 0);
                }
            }
            //现金支付
        } else if (payType === 1) {
            if (redPayStatus === 0) {
                if (parseInt($(this).attr("goldStatus")) === 0) {
                    //使用金币抵扣
                    var coin = parseFloat($(".coinL").html());
                    if(coin===0) return false;
                    //如何金币大于或等于需要支付的现金
                    if (coin >= parseFloat(localStorage.totalPrice)) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".coinPayD").html(parseFloat(localStorage.totalPrice).toFixed(2));
                    } else if (coin < parseFloat(localStorage.totalPrice)) {
                        $(".cashPay").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                        $(".coinPayD").html(coin.toFixed(2));
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("goldStatus", 1);
                } else if (parseInt($(this).attr("goldStatus")) === 1) {
                    //取消金币抵扣
                    $(".cashPay").html((parseFloat(localStorage.totalPrice)).toFixed(2));
                    $(".wxPay").html((parseFloat(localStorage.totalPrice)).toFixed(2));
                    $(".coinPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("goldStatus", 0);
                }
            } else if (redPayStatus === 1) {
                var red = parseFloat($(".redL").html());
                console.log(red);
                console.log(totalCash);
                if (parseInt($(this).attr("goldStatus")) === 0) {
                    //使用金币抵扣
                    var coin = parseFloat($(".coinL").html());
                    if(coin===0) return false;
                    console.log(coin);
                    console.log(parseFloat(localStorage.totalPrice));
                    if(coin >= parseFloat(localStorage.totalPrice)) {
                        $(".coinPayD").html(parseFloat(localStorage.totalPrice).toFixed(2));
                        $(".wxPay").html("0.00");
                        $(".cashPay").html("0.00");
                        $(".redPayD").html("0.00");
                    }else if(coin<parseFloat(localStorage.totalPrice)) {
                        $(".coinPayD").html(coin.toFixed(2));
                        if(red>parseFloat(localStorage.totalPrice)-coin) {
                            $(".wxPay").html("0.00");
                            $(".cashPay").html("0.00");
                            $(".redPayD").html((parseFloat(localStorage.totalPrice)-coin).toFixed(2));
                        }else if(red<parseFloat(localStorage.totalPrice)-coin) {
                            $(".wxPay").html((parseFloat(localStorage.totalPrice)-coin-red).toFixed(2));
                            $(".cashPay").html((parseFloat(localStorage.totalPrice)-coin-red).toFixed(2));
                            $(".redPayD").html(red.toFixed(2));
                        }
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("goldStatus", 1);
                } else if (parseInt($(this).attr("goldStatus")) === 1) {
                    console.log(99999999)
                    //取消金币抵扣 
                    if(parseFloat(localStorage.totalPrice) - red > 0) {
                        $(".cashPay").html((parseFloat(localStorage.totalPrice) - red).toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice) - red).toFixed(2));
                        $(".redPayD").html(red.toFixed(2));
                    }else if(parseFloat(localStorage.totalPrice) - red <= 0) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".redPayD").html(localStorage.totalPrice);
                    }
                    $(".coinPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("goldStatus", 0);
                }
            }
        }
    });
    //使用红包抵扣
    $(".orderDetail").on("click", ".redPayBtn", function () {
        var payType = parseInt($(".diamondBtn").attr("payType"));
        var goldStatus = parseInt($(".goldBtn").attr("goldStatus"));
        // if (goldStatus === 0) {
        //现金加钻石支付
        if (payType === 2) {
            if (goldStatus === 0) {
                // if (totalCash === 0) return false;
                if (parseInt($(this).attr("redPayStatus")) === 0) {
                    //使用金币抵扣
                    var red = parseFloat($(".redL").html());
                    if(red===0) return false;
                    //如果金币大于或等于需要支付的现金
                    if (red >= totalCash) {
                        console.log(00000000)
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".redPayD").html(totalCash.toFixed(2));
                    } else if (red < totalCash) {
                        $(".cashPay").html((totalCash - red).toFixed(2));
                        $(".wxPay").html((totalCash - red).toFixed(2));
                        $(".redPayD").html(red.toFixed(2));
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("redPayStatus", 1);
                } else if (parseInt($(this).attr("redPayStatus")) === 1) {
                    //取消金币抵扣
                    $(".cashPay").html(totalCash.toFixed(2));
                    $(".wxPay").html(totalCash.toFixed(2));
                    $(".redPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("redPayStatus", 0);
                }
            } else if (goldStatus === 1) {
                var coin = parseFloat($(".coinL").html());
                console.log(coin);
                console.log(totalCash);
                if (parseInt($(this).attr("redPayStatus")) === 0) {
                    //使用金币抵扣
                    var red = parseFloat($(".redL").html());
                    if(red===0) return false;
                    console.log(red);
                    //如果金币大于或等于需要支付的现金
                    if(coin-totalCash>=0) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".redPayD").html("0.00");
                    }else if(coin-totalCash<0) {
                        if(red>=totalCash-coin) {
                            $(".cashPay").html("0.00");
                            $(".wxPay").html("0.00");
                            $(".redPayD").html((totalCash-coin).toFixed(2));
                        }else if(red<totalCash-coin) {
                            $(".cashPay").html((totalCash-coin-red).toFixed(2));
                            $(".wxPay").html((totalCash-coin-red).toFixed(2));
                            $(".redPayD").html(red.toFixed(2));
                        }
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("redPayStatus", 1);
                } else if (parseInt($(this).attr("redPayStatus")) === 1) {
                    console.log(99999999)
                    //取消金币抵扣
                    if (totalCash - coin > 0) {
                        $(".cashPay").html((totalCash - coin).toFixed(2));
                        $(".wxPay").html((totalCash - coin).toFixed(2));
                    } else if (totalCash - coin < 0) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".coinPayD").html(totalCash.toFixed(2));
                    }
                    $(".redPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("redPayStatus", 0);
                }
            }
            //现金支付
        } else if (payType === 1) {
            if (goldStatus === 0) {
                if (parseInt($(this).attr("redPayStatus")) === 0) {
                    //使用金币抵扣
                    var red = parseFloat($(".redL").html());
                    if(red===0) return false;
                    //如何金币大于或等于需要支付的现金
                    if (red >= parseFloat(localStorage.totalPrice)) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".redPayD").html(parseFloat(localStorage.totalPrice).toFixed(2));
                    } else if (red < parseFloat(localStorage.totalPrice)) {
                        $(".cashPay").html((parseFloat(localStorage.totalPrice) - red).toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice) - red).toFixed(2));
                        $(".redPayD").html(red.toFixed(2));
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("redPayStatus", 1);
                } else if (parseInt($(this).attr("redPayStatus")) === 1) {
                    //取消金币抵扣
                    $(".cashPay").html((parseFloat(localStorage.totalPrice)).toFixed(2));
                    $(".wxPay").html((parseFloat(localStorage.totalPrice)).toFixed(2));
                    $(".redPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("redPayStatus", 0);
                }
            } else if (goldStatus === 1) {
                var coin = parseFloat($(".coinL").html());
                console.log(parseInt($(".redPayBtn").attr("redPayStatus")));
                console.log(coin);
                if (coin >= parseFloat(localStorage.totalPrice) && parseInt($(".redPayBtn").attr("redPayStatus")) === 0) {
                    return false;
                }
                console.log(totalCash);
                if (parseInt($(this).attr("redPayStatus")) === 0) {
                    var red = parseFloat($(".redL").html());
                    if(red===0) return false;
                    console.log(red);
                    if (red >= (parseFloat(localStorage.totalPrice) - coin)) {
                        console.log(00000000)
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".redPayD").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                    } else if (red < (parseFloat(localStorage.totalPrice) - coin)) {
                        $(".cashPay").html((parseFloat(localStorage.totalPrice) - coin - red).toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice) - coin - red).toFixed(2));
                        $(".redPayD").html(red.toFixed(2));
                    }
                    $(".cashPay").html();
                    $(this).find("img").attr("src", "../../static/img/btn_off@3x.png");
                    $(this).attr("redPayStatus", 1);
                } else if (parseInt($(this).attr("redPayStatus")) === 1) {
                    console.log(99999999);
                    if (parseFloat(localStorage.totalPrice) - coin > 0) {
                        $(".cashPay").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                        $(".wxPay").html((parseFloat(localStorage.totalPrice) - coin).toFixed(2));
                    } else if (parseFloat(localStorage.totalPrice) - coin < 0) {
                        $(".cashPay").html("0.00");
                        $(".wxPay").html("0.00");
                        $(".coinPayD").html(localStorage.totalPrice);
                    }
                    $(".redPayD").html("0.00");
                    $(this).find("img").attr("src", "../../static/img/btn_UN@3x.png");
                    $(this).attr("redPayStatus", 0);
                }
            }
        }
    });
});